package com.example.tests;

import static org.junit.Assert.assertEquals;

import org.testng.annotations.Test;

import com.example.model.SortedListOf;
import com.example.model.User;
import com.example.pages.UserPage;

public class CreateNewUserTest extends TestBase {

	@Test
	public void testCreateNewUser() {
		UserPage userPage = goToMainPage().logInwithValidCredentials(login,
				oldPass).goToUserManagement();

		SortedListOf<User> oldUserList = userPage.getUsers();

		User user = new User().withName(("Adam")).withEmail("test1@test.com")
				.withPass("111111");
		if (oldUserList.contains(user)) {
			userPage.deleteUser(user);
			oldUserList = userPage.getUsers();
		}
		userPage.createUser(user);

		SortedListOf<User> newUserList = userPage.getUsers();

		assertEquals(newUserList, oldUserList.withAdded(user));
	}
}
